//
//  XHMainViewController.m
//  围脖
//
//  Created by 魏兴浩 on 15/12/11.
//  Copyright © 2015年 wxh. All rights reserved.
//

#import "XHMainViewController.h"
#import "XHHomeViewController.h"
#import "XHMessageViewController.h"
#import "XHDiscoverViewController.h"
#import "XHProfileViewController.h"
#import "XHTabBar.h"
@interface XHMainViewController ()
@property (nonatomic,strong)UIButton *zhuanxieBtn;
@end

@implementation XHMainViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    //第二种设置撰写按钮的方法
    XHTabBar *writBtn = [[XHTabBar alloc]initWithFrame:self.tabBar.frame];
//
    [self setValue:writBtn forKey:@"tabBar"];

}
-(void)loadView{
    [super loadView];
    
    //创建子控制器
    XHHomeViewController *homeVc = [[XHHomeViewController alloc]init];
    //调用简化方法
    [self addChildVC:homeVc title:@"主页" norImageName:@"tabbar_home_highlighted"];
    
    //消息
    XHMessageViewController *messageVc = [[XHMessageViewController alloc]init];
    [self addChildVC:messageVc title:@"消息" norImageName:@"tabbar_message_center_highlighted"];
    
    //创建占位控制器（撰写按钮）
    UITableViewController *zhanweiVc = [[UITableViewController alloc]init];
    [self addChildVC:zhanweiVc title:nil norImageName:nil];
    
    //发现
    XHDiscoverViewController *discoverVc = [[XHDiscoverViewController alloc]init];
    [self addChildVC:discoverVc title:@"发现" norImageName:@"tabbar_discover_highlighted"];
    
    //我
    XHProfileViewController *profileVc = [[XHProfileViewController alloc]init];
    [self addChildVC:profileVc title:@"我" norImageName:@"tabbar_profile_highlighted"];
}

#pragma mark - 抽取代码（简化）
-(void)addChildVC:(UITableViewController *)tabbleVc title:(NSString *)title norImageName:(NSString *)imageName{
    
    UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:tabbleVc];
      [self addChildViewController:nvc];
    tabbleVc.title = title;
    nvc.tabBarItem.title = title;
    nvc.tabBarItem.image = [UIImage imageNamed:imageName];
    
  
}

#pragma mark - 撰写按钮
//////设置撰写按钮frmae
//-(void)viewWillAppear:(BOOL)animated{
//    //一定要调用父类这个方法
//    [super viewWillAppear:animated];
//    //获得tabBar的总个数
//    CGFloat width = self.tabBar.bounds.size.width/5;
//    //计算frame
//    CGRect frame = CGRectMake(2 * width-5, 0, width +10, self.tabBar.bounds.size.height+5);
//    //设置frame
//    self.zhuanxieBtn.frame = frame;
//
//}

#pragma mark -撰写按钮点击事件
-(void)zhuanxieBtnClick{
    NSLog(@"点击撰写按钮");
}
#pragma mark -懒加载
////撰写按钮
//-(UIButton *)zhuanxieBtn{
//    if (_zhuanxieBtn == nil) {
//        _zhuanxieBtn = [[UIButton alloc]init];
//        
//        //设置按钮背景图片
//        [_zhuanxieBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
//        [_zhuanxieBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
//        
//        //设置按钮点击图片
//        [_zhuanxieBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
//        [_zhuanxieBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
//      
//        //添加到当前的tabBar中
//        [self.tabBar addSubview:_zhuanxieBtn];
//        
//        //添加点击事件
//        [_zhuanxieBtn addTarget:self action:@selector(zhuanxieBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    }
//    return _zhuanxieBtn;
//}
@end
